{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>大纲<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#简介\" data-toc-modified-id=\"简介-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>简介</a></span></li></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 简介\n",
    "函数对象的`__annotations__`属性保存着对该函数的参数,返回值解释的信息.\n",
    "那么:\n",
    "1. 编程中如何向这个`属性`中写入信息?\n",
    "    - 参数: 在参数名后面加上`: 类型`\n",
    "    - 返回值: 在`:`前面加上`-> 类型`\n",
    "1. 如何读取?\n",
    "    - 函数名`.__annotations__`    \n",
    "1. 这个属性有什么用处?\n",
    "    - 做类型检查(自定义装饰器)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-24T06:46:01.992391Z",
     "start_time": "2018-05-24T06:46:01.987419Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 : wangkaixuan\n",
      "1 : wangkaixuan\n",
      "2 : wangkaixuan\n",
      "3 : wangkaixuan\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'value': str, 'times': int, 'return': bool}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def p(value:str, times:int) -> bool:\n",
    "    for i in range(times):\n",
    "        print(i,':',value)\n",
    "p('wangkaixuan',4) \n",
    "p.__annotations__"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda all lib",
   "language": "python",
   "name": "base"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "大纲",
   "title_sidebar": "目录",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
